package com.uco.sample;

public class Operator {
    public static void main(String[] args) {
//        test(5, 2);
//        test1(5);
//        test2(10, 2);
        test5(5, 2);
    }


    // 常见的算数运算符
    // + 号也可以用于字符串拼接，从左往右能算则算，不能算则直接拼接
    // / 号的最终结果，取决于最大的类型是什么
    public static void test(int a, int b) {
        System.out.println("a + b = " + (a + b));
        System.out.println("a - b = " + (a - b));
        System.out.println("a * b = " + (a * b));
        System.out.println("a / b = " + (a / b));
        System.out.println("a % b = " + (a % b));
        System.out.println(5 + 'a' + "Gold"); // 输出：102Gold
        System.out.println(5.0/2);
        System.out.println(5/2);
    }

    // 接收一个整数，演示自增和自减的结果
    public static void test1(int a) {
        // a++/++a = a = a + 1
        System.out.println("a = " + a);
        System.out.println("a++ = " + a++); // 先用再加
        System.out.println("++a = " + ++a); // 先加再用
        System.out.println("a-- = " + a--); // 先用再减
        System.out.println("--a = " + --a); // 先减再用
    }

    // 常见的赋值运算符
    // 常见算数运算符是针对 int 类型的，非 int 类型的，会自动转换成 a 的类型
    public static void test2(int a, int b) {
        System.out.println("a = " + a);
        System.out.println("a += b = " + (a += b)); // a = (a的类型) a + b
        System.out.println("a -= b = " + (a -= b)); // a = (a的类型) a - b
        System.out.println("a *= b = " + (a *= b)); // a = (a的类型) a * b
        System.out.println("a /= b = " + (a /= b)); // a = (a的类型) a / b
    }

    // 常见的关系运算符
    public static void test3(int a, int b) {
        System.out.println("a > b = " + (a > b));
        System.out.println("a < b = " + (a < b));
        System.out.println("a >= b = " + (a >= b));
        System.out.println("a <= b = " + (a <= b));
        System.out.println("a == b = " + (a == b));
    }

    // 常见的逻辑运算符
    public static void test4(boolean a, boolean b) {
        System.out.println("a && b = " + (a && b));
        System.out.println("a || b = " + (a || b));
        System.out.println("!a = " + !a);
    }

    // 三元运算符
    // 三元运算符的语法：
    // 条件 ? 表达式1 : 表达式2
    // 条件为 true，则返回表达式1，否则返回表达式2
    public static void test5(int a, int b) {
        System.out.println("a > b ? a : b = " + (a > b ? a : b));
    }
}